﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Attendences.Framework.Entity;
using Attendences.Framework.BusinessLogic;

public partial class Page_OtherUserManage : BaseAuthenticationPage
{
    public string SearchClauseList
    {
        get
        {
            if (ViewState["SearchClauseList"] == null)
                ViewState["SearchClauseList"] = "1=1";
            return ViewState["SearchClauseList"].ToString();
        }
        set
        {
            ViewState["SearchClauseList"] = value;
        }
    }

    public string SearchClauseItem
    {
        get
        {
            if (ViewState["SearchClauseItem"] == null)
                ViewState["SearchClauseItem"] = "1=1";
            return ViewState["SearchClauseItem"].ToString();
        }
        set
        {
            ViewState["SearchClauseItem"] = value;
        }
    }

    protected DataTable AttendList
    {
        get
        {
            if (ViewState["AttendList"] == null)
                ViewState["AttendList"] = new DataTable();
            return ViewState["AttendList"] as DataTable;
        }
        set
        {
            ViewState["AttendList"] = value;
        }
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        this.Title = "值班列表";

        if (!IsPostBack)
        {
            this.Order.OrderColumn = "CreateTime";
            this.Order.OrderDirection = "DESC";
            BindData();
        }
    }

    protected override void Pager_PageChanged(object sender, EventArgs e)
    {
        BindData();
        base.Pager_PageChanged(sender, e);
    }

    protected override void Order_OrderChanged(object sender, EventArgs e)
    {
        BindData();
        base.Order_OrderChanged(sender, e);
    }

    private void BindData()
    {
        int recordCount = 0;
        AttendList =  BLOtherUser.getUserList(SearchClauseList, Pager.PageIndex, Pager.PageSize, string.Format("{0} {1}", this.Order.OrderColumn, this.Order.OrderDirection), ref recordCount);
        Pager.RecordCount = recordCount;
        rptAttendences.DataSource = AttendList;
        rptAttendences.DataBind();
    }

    protected void btnAdvancedSearch_Click(object sender, EventArgs e)
    {
        SearchClauseItem = "1=1";
        if (tbUserName.Text != string.Empty)
            SearchClauseItem += string.Format(" AND {0} LIKE N'%{1}%'", OtherUser.SQLCOL_DISPLAYNAME, tbUserName.Text.Replace("'", "''").Replace("%", "[%]"));

        tbUserName.Text = string.Empty;
        BindData();
    }
    protected void btnRefresh_Click(object sender, EventArgs e)
    {
        BindData();
    }
}